///<reference path="../jquery/jquery.d.ts" />
class Debug {
	public isdebug = false;
	private textObj: JQuery = null;
	public constructor() {
		if (location.href.indexOf("debug=true") > 1) {
			this.isdebug = true;
		}
		if (this.isdebug) {
			let mthis = this;
			$(() => {
				mthis.init();
			});
		}
	}
	private isTop: boolean = false;
	private height = '180px';
	private backgroundColor = 'rgba(0, 0, 0, 0.5);';
	private init() {
		if (!this.isdebug) {
			return;
		}
		$('body').addClass("debug");
		this.textObj = $(`<textarea class="debuglog"  readonly="readonly" style="width: 100%;height:` + this.height + `;
		position: fixed;z-index: 9999;bottom: 0;left:0;padding: 0;margin: 0;    font-size:18px;
		 background-color:`+ this.backgroundColor + `;color:white;"></textarea>`);
		$('body').append(this.textObj);
		let mthis = this;
		this.textObj.on('click', () => {
			mthis.touchTextObj();
		});
		this.textObj.val(this._logstr);
		this.zhuangtaiP = $(`<p class='zhuangtaidebug' style="
    position: fixed;
    top: 1px;
    background-color: rgba(0, 0, 0, 0.07);
    width: 100%;
    color: rgba(255, 255, 255, 0.76);
    font-size: 1rem;
"></p>`);
		$('body').append(this.zhuangtaiP);

		let clear = $(`<button class="debuglog"   style="
    position: fixed;
    bottom: 180px;    font-size:19px;
    z-index: 999999;
"class="clearico">clear</button>`);
		$('body').append(clear);
		clear.on("click", () => {
			this._logstr = '';
			this.textObj.val(this._logstr);
		});

		let str = '';
 
		//this.zhuangtai("sss");


		this.zhuangtaiP.on("touchstart",()=>{
			if($('#canvas-frame').hasClass('on')){
				$('#canvas-frame').removeClass('on');
			}else{
				$('#canvas-frame').addClass('on');
			} 
		});
		 



	}

	/** 状体更新标签 */
	private zhuangtaiP: JQuery = null;

	/** 如果点击了2次,隐藏掉 */
	private cishu = 0;
	private touchTextObj() {  //if(1) return;
		this.cishu++;
		if (this.cishu === 10) {
			this.textObj.hide();
			return;
		}
		this.isTop = !this.isTop;
		if (this.isTop) {
			this.textObj.css('bottom', 'initial');
			this.textObj.css('top', '0');
		} else {
			this.textObj.css('bottom', '0');
			this.textObj.css('top', 'initial');
		}
	}
	private _str: string;
	public zhuangtai(str: string) {
		if (!this.isdebug || this._str == str) {
			return;
		}
		this._str = str;
		this.zhuangtaiP.html(str);
	}

	private _logstr: string = '';
	private _up: string = '';
	public log(text: any,cons=false) {
		if(cons){
			console.log('%c '+text,'color:red;');
		}
		if (!this.isdebug) {
			return;
		}

		if (typeof (text) == 'object') {
			console.log(text);
			text = JSON.stringify(text);
		}
		
		
		/*	if(this._up==text){
				///return;
				text+=text+'+1';
			}*/
		if (this._up === text) {
			text += '+';
		}
		this._up = text;
		this._logstr = text + "\r\n" + this._logstr;
		if (this.textObj) {
			this.textObj.val(this._logstr);
		}

	}

}
let debug = new Debug();